package com.eos.control.action.activity;

import com.eos.business.service.SysActivityBusinessService;
import com.eos.common.tool.ConstantTool;
import com.eos.common.tool.ObjectUtils;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.ActivtyMappModel;
import com.eos.orm.mybatis.model.ActivtyMappSales;
import com.eos.orm.mybatis.model.SysUser;

public class SaveModelSalesSetAction extends AbstractBaseAction {
	private static final long serialVersionUID = 6978699360124300328L;
	private Integer mappId;
	private Integer salesId;
	private Integer comboId;
	private Integer comboCycle; 
	private String salesPrice;
	private String isSubsidy;

	public void setMappId(Integer mappId) {
		this.mappId = mappId;
	}

	public void setSalesId(Integer salesId) {
		this.salesId = salesId;
	}

	public void setComboId(Integer comboId) {
		this.comboId = comboId;
	}

	public void setComboCycle(Integer comboCycle) {
		this.comboCycle = comboCycle;
	}

	public void setSalesPrice(String salesPrice) {
		this.salesPrice = salesPrice;
	}

	public void setIsSubsidy(String isSubsidy) {
		this.isSubsidy = isSubsidy;
	}

	@Override
	public String execute() {
		try {
			SysUser user = (SysUser) getSession().getAttribute("SysUser");
			String userId = user.getId()+"";
			String strTime = ObjectUtils.formatDate(null, "yyyy-MM-dd HH:mm:ss");
			ActivtyMappSales ams = new ActivtyMappSales();
			ams.setComboCycle(comboCycle);
			ams.setComboId(comboId);
			ams.setDealFlag(ConstantTool.STATUS_OK);
			ams.setInsertTime(strTime);
			ams.setInsertUserId(userId);
			ams.setIsSubsidy(isSubsidy);
			ams.setMappId(mappId);
			ams.setModifyTime(strTime);
			ams.setSalesId(salesId);
			ams.setSalesPrice(salesPrice);
			ams.setStatus(ConstantTool.STATUS_OK);
			ams.setUpdateUserId(userId);
			SysActivityBusinessService sabs = new SysActivityBusinessService();
			String exeStatus = sabs.saveActivitySales(ams);
			if("SUCCESS".equals(exeStatus)){
				statusCode = "200";
				message = "保存型号套餐关系信息成功!";
				
				//保存后修改活动型号关系中的套餐配置字段(combo_config)
				ActivtyMappModel amm = new ActivtyMappModel();
				amm.setId(mappId);
				amm.setComboConfig("1");
				sabs.updateActivityModelPKSelective(amm);
			}else{
				statusCode = "300";
				message = "系统繁忙, 保存型号套餐关系信息失败!";
			}
		} catch (Exception e) {
			e.printStackTrace();
			statusCode = "300";
			message = "系统异常, 保存型号套餐关系信息失败!";
		}
		return SUCCESS;
	}
}
